package org.demo.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

/**
 * 
 * @author  
 * @date    2010-11-11
 * @file    org.demo.json.JsonMain.java
 */
public class JsonMain {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args)throws Exception {
		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
		Map<String,String> map1 = new HashMap<String,String>();
		Map<String,String> map2 = new HashMap<String,String>();
		map1.put("id", "10");
		map1.put("name", "zhangsan");
		map2.put("id", "12");
		map2.put("name", "lisi");
		list.add(map1);
		list.add(map2);
		// object to json
		JSONArray jsonArray = JSONArray.fromObject(list);
		String str = jsonArray.toString();
		System.out.println(str);
		// json to object
		jsonArray = JSONArray.fromObject(str);
		list = new ArrayList(JSONArray.toCollection(jsonArray));
		// System.out.println(list);
	}

}
